<template>
  <view class="container">
    <view v-if="sts == 0">
      <view class="pay-sts fail">
        支付失败
      </view>
      <view class="tips">
        请在
        <text class="warn">
          30分钟
        </text>内完成付款
      </view>
      <view class="tips">
        否则订单会被系统取消
      </view>
      <view class="btns">
        <text
          class="button checkorder"
          @tap="toOrderList"
        >
          查看订单
        </text>
        <text
          class="button payagain"
          @tap="payAgain"
        >
          重新支付
        </text>
      </view>
    </view>

    <view v-if="sts == 1">
      <view class="pay-sts succ">
        支付成功
      </view>
      <view class="tips">
        感谢您的购买
      </view>
      <view class="btns">
        <text
          class="button checkorder"
          @tap="toOrderList"
        >
          查看订单
        </text>
        <text
          class="button shopcontinue"
          @tap="toIndex"
        >
          继续购物
        </text>
      </view>
    </view>
  </view>
</template>

<script setup>
import {request} from "../../utils/request-test";

export default {
  data(){
    return{
      sts:0,
      orderNumbers:'',

    }
  },
  methods:{
    toOrderList(){
      uni.navigateTo({
        url: '/pages/orderList/orderList?sts=0'
      })
    },
    toIndex(){
      uni.switchTab({
        url: '/pages/index'
      })
    },
    payAgain(){
      uni.showLoading({
        mask: true
      })
     /* http.request({
        url: '/p/order/pay',
        method: 'POST',
        data: {
         payType: 1,
          orderNumbers: orderNumbers.value
        }
       })*/
          request("/p/order/pay",'POST',{
            payType: 1,
            orderNumbers: this.orderNumbers
          })
          .then(({ data }) => {
            uni.hideLoading()
            uni.requestPayment({
              timeStamp: data.timeStamp,
              nonceStr: data.nonceStr,
              package: data.packageValue,
              signType: data.signType,
              paySign: data.paySign,
              success: () => {
                uni.redirectTo({
                  url: '/pages/index/payResult?sts=1&orderNum=' + this.orderNumbers
                })
              }
            })
          })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options){
  this.sts= options.sts
  this.orderNumbers= options.orderNumbers
},

}
</script>

<style scoped lang="scss">
.pay-sts {
  font-size: 40rpx;
  margin-top: 100rpx;
  padding: 30rpx 0;
  text-align: center;
}
.pay-sts.fail {
  color: #f43530;
}
.pay-sts.succ {
  color: #19be6b;
}
.btns {
  margin-top: 50rpx;
  text-align: center;
  .button {
    border-radius: 10rpx;
    font-size: 28rpx;
    background: #fff;
    color: #333;
    padding: 20rpx 35rpx;
    width: 300rpx;
    margin: 0 20rpx;
    text-align: center;
  }
  .button.checkorder {
    background: #19be6b;
    color: #fff;
    margin-bottom: 20rpx;
    border: 2rpx solid #19be6b;
  }
  .button.payagain {
    background: #fff;
    border: 2rpx solid #f90;
    color: #f90;
  }
  .button.shopcontinue {
    background: #fff;
    border: 2rpx solid #19be6b;
    color: #19be6b;
  }
}
.tips {
  font-size: 28rpx;
  color: #999;
  text-align: center;
  .warn {
    color: #f43530;
  }
}

</style>
